<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>编辑文章</title> <#include "head.ftl" />
</head>
<body>
	<div class="body-box">
		<div class="rhead">
			<div class="rpos">当前位置: 文章管理 - 生成HTML</div>
			<form class="ropt">
				<input type="button" value="返回"
					onclick="location.href='${st.domain}/article/list'" />
			</form>
			<div class="clear"></div>
		</div>
		<form id="gen_form">
			<table width="100%" class="pn-ftable" cellpadding="2" cellspacing="1"
				border="0">
				<tr>
					<td width="10%" class="pn-flabel pn-flabel-h"><span
						class="pn-frequired">*</span>模板类型:</td>
					<td colspan="1" class="pn-fcontent">
						<select id="templateType">
							<option value="${st.domain}/article/generateHelpDo/json">帮助中心</option>
						</select>
					</td>
				</tr>
				<tr>
					<td class="pn-flabel pn-flabel-h"><span class="pn-frequired">*</span>模板:</td>
					<td colspan="1" class="pn-fcontent"><input type="text"
						name="template" value="/help.ftl"></td>
				</tr>
				<tr>
					<td class="pn-flabel pn-flabel-h"><span class="pn-frequired">*</span>内容分类:
						<input type="hidden" id="catId" name="catId" value="112">
					</td>
					<td colspan="1" class="pn-fcontent"><input type="text"
						id="categoryName" value="帮助中心" readonly="readonly">
					</td>
				</tr>
				<tr>
					<td class="pn-flabel pn-flabel-h"><span class="pn-frequired">*</span>HTML目录:</td>
					<td colspan="1" class="pn-fcontent"><input type="text"
						name="generatePath" value="/static.war" style="width:300px">
					</td>
				</tr>
				<tr>
					<td colspan="4" class="pn-fbutton"><input type="button"
						id="submitBt" value="提交" /> &nbsp; <input type="reset" value="重置" />
					</td>
				</tr>
			</table>
		</form>
		<div id="generatingMsg" style="font-size:15px;color:blue;"></div>
	</div>
</body>
<script>
	
	// 文章分类选择
	$("#categoryName").categoryFloatPanel({
		type: 1,
		onSelect: function(treeId, treeNode) {
			$("#catId").val(treeNode.catId);
			$("#categoryName").val(treeNode.name);
		}
	});
	
	// 事件:提交
	$("#submitBt").click(function() {
		$("#gen_form").hide();
		$("#generatingMsg").html("现在开始生成HTML....请等待!");
		generate($("#gen_form").serialize());
	});
	
	function generate(params) {
		$.post($("#templateType").val(), params, function(data) {
			if (data.status !== 0) {
				alert(data.message);
				return;
			}
			var pageInfo = data.result;
	
			if (pageInfo.nowPage < pageInfo.totalPage) {
				$("#generatingMsg").html("共计:" + pageInfo.totalResult + ",已生成:" + (pageInfo.nowPage * pageInfo.pageSize) + 
				",操作还在处理中....请等待!");

				generate($("#gen_form").serialize() + "&pi.nowPage=" + (++pageInfo.nowPage));
			} else {
				$("#gen_form").show();
				$("#generatingMsg").html("操作完成!共计:" + pageInfo.totalResult);
			}
		});
	}
	
</script>
</html>